package com.aw.qzblog.controller;

import com.aw.qzblog.annotation.AdminCheck;
import com.aw.qzblog.common.Result;
import com.aw.qzblog.entity.dto.user.UserLoginRequest;
import com.aw.qzblog.entity.dto.user.UserRegisterRequest;
import com.aw.qzblog.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/register")
    public Result register(@RequestBody UserRegisterRequest userRegisterRequest) {
        return userService.register(userRegisterRequest);
    }

    @PostMapping("/login")
    public Result login(@RequestBody UserLoginRequest userLoginRequest) {
        return userService.login(userLoginRequest);
    }

    @GetMapping("/searchByName/{username}")
    public Result searchByName(@PathVariable String username) {
        return userService.searchByName(username);
    }


    @GetMapping("/page/{pageNum}")
    @AdminCheck
    public Result page(@PathVariable int pageNum) {
        return userService.userPage(pageNum);
    }

    @GetMapping("/change/status/{userId}/{statusId}")
    @AdminCheck
    public Result changeStatus(@PathVariable Long userId, @PathVariable Integer statusId) {
        return userService.changeStatus(userId, statusId);
    }
}
